﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using yncTech.Common;
using yncTech.BusinessObjects;

public partial class Admin_Sys_Sys001a : AdminBasePage
{
    public decimal? systemId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString[TSSystemMetadata.ColumnNames.SystemId] != null)
        {
            systemId = decimal.Parse(Request.QueryString[TSSystemMetadata.ColumnNames.SystemId]);
        }
        if (!IsPostBack)
        {
            switch (ActionType)
            {
                case OperationType.Add:
                    btnSave.Text = "新增";
                    radActive.Checked = true;
                    break;
                case OperationType.Update:
                    if (systemId.HasValue)
                    {
                        TSSystem system = new TSSystem();
                        if (system.LoadByPrimaryKey(systemId.Value))
                        {
                            txtSysName.Text = system.SystemName;
                            if (system.IsActive.HasValue && system.IsActive.Value == (int)ActiveStatus.Active)
                            {
                                radActive.Checked = true;
                            }
                            else
                            {
                                rad24.Checked = true;
                            }
                        }
                        btnSave.Text = "修改";
                    }
                    break;
                case OperationType.Delete:
                    btnSave_Click(null, null);
                    break;
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            TSSystem system = new TSSystem();
            switch (ActionType)
            {
                case OperationType.Add:
                    system.SystemName = txtSysName.Text.Trim();
                    system.IsActive = radActive.Checked ? 1 : 0;
                    system.CreatedBy = LoginUserInfo.CurrentUser.LoginName;
                    system.Save();
                    break;
                case OperationType.Update:
                    system.LoadByPrimaryKey(systemId.Value);
                    system.SystemName = txtSysName.Text.Trim();
                    system.CreatedBy = LoginUserInfo.CurrentUser.LoginName;
                    system.IsActive = radActive.Checked ? 1 : 0;
                    system.Save();
                    break;
                case OperationType.Delete:
                    system.LoadByPrimaryKey(systemId.Value);
                    system.MarkAsDeleted();
                    system.Save();
                    WebHelper.GotoParent();
                    break;
            }
            WebHelper.CloseDialog(true);
        }
        catch (Exception ex)
        {
            lbMessage.Text = ex.Message;
        }
    }

    protected void btnClose_Click(object sender, EventArgs e)
    {
        WebHelper.CloseDialog();
    }
}